import 'dart:io';

    

import './Env.dart';
import "../base/basewidget/HttpUtils/HttpBaseConst.dart";

class EnvInit {
  static const String BASE_H5_URL_HEAD = "http://www";
  static const String URL_END = ".platform.ahjtest.top/";
  static const String URLH5_END = ".ehsweb.ahjtest.top/";

  static void initUri() {
    /** 查找变量 */
    Env env = findEnv();

    // 设置当前环境API地址
    String name = env.name.toLowerCase();

    // 开发环境后端地址不使用https
    String protocol = "http:";
    String apiUrlHead = protocol + "//api.";
    String apiValue = name;
    String end = URL_END;
    String h5end = URLH5_END;
    HttpBaseConst.baseH5Url =(BASE_H5_URL_HEAD + h5end);
    // HttpBaseConst.serverUrl =  (apiUrlHead + apiValue + end);
    HttpBaseConst.serverUrl = 'http://api.test01.platform.ahjtest.top/';
    // HttpBaseConst.serverUrl = "http://api.platform.anhuanjia.com/"; //test环境
  }

  static Env findEnv() {
    /** NND  ，必须用 const才能读取 环境变量的值，否则读取不到，哪个鬼才想出来的损招  20230415 */
    const bool isReleaseMode = const bool.fromEnvironment("dart.vm.product");
    String envString = "release";
    if (Platform.isIOS) {
      const String envRawString = !isReleaseMode ? "test01" : "release";
      envString = envRawString.toLowerCase();
    } else {
      const String envRawString = String.fromEnvironment('ENV');
      envString = envRawString.toLowerCase();
    }
    Env env = Env.RELEASE; //默认值用release
    for (var item in Env.values) {
      if (item.name.toLowerCase() == envString) {
        env = item;
        break;
      }
    }

    return env;
  }
}
